home *** CD-ROM | disk | FTP | other *** search
/ PC Open 107 / PC Open 107 CD 1.bin / CD1 / INTERNET / COPIA SITI / Getleft / getleft-setup-notcl.exe / {app} / scripts / mainWin.tcl < prev    next >
Encoding:
Text File  |  2004-06-07  |  49.9 KB  |  1,346 lines

  1. ################################################################################
  2. ################################################################################
  3. ##                          mainwin.tcl
  4. ################################################################################
  5. ################################################################################
  6. ## Defines the main window of Getleft, the menus and such
  7. ################################################################################
  8. ################################################################################
  9. ## (c) 2001-2004 AndrΘs Garcφa Garcφa. fandom@retemail.es
  10. ## You may distribute the contents of this file under the terms of the GPL v2
  11. ################################################################################
  12. ################################################################################
  13.  
  14. namespace eval iconNS {
  15.  
  16. ################################################################################
  17. # DefineIconImages
  18. #     Prepares the images for the icons in the taskbar so that Tcl can use them
  19. ################################################################################
  20. proc DefineIconImages {} {
  21.     global dirGetleft
  22.     variable iconImages
  23.  
  24.     set iconNS::iconImages(url)     [image create photo             \
  25.             -file [file join "$dirGetleft(icons)" url.gif]]
  26.     set iconNS::iconImages(start)   [image create photo             \
  27.             -file [file join "$dirGetleft(icons)" start.gif]]
  28.     set iconNS::iconImages(auto)    [image create photo             \
  29.             -file [file join "$dirGetleft(icons)" auto.gif]]
  30.     set iconNS::iconImages(delay)   [image create photo             \
  31.             -file [file join "$dirGetleft(icons)" delay.gif]]
  32.     set iconNS::iconImages(log)     [image create photo             \
  33.             -file [file join "$dirGetleft(icons)" log.gif]]
  34.     set iconNS::iconImages(fileLog) [image create photo             \
  35.             -file [file join "$dirGetleft(icons)" fileLog.gif]]
  36.     set iconNS::iconImages(get)     [image create photo             \
  37.             -file [file join "$dirGetleft(images)" get.gif]]
  38.     set iconNS::iconImages(help)    [image create photo             \
  39.             -file [file join "$dirGetleft(icons)" help.gif]]
  40.  
  41.     set iconNS::iconImages(update)  [image create photo             \
  42.             -file [file join "$dirGetleft(icons)" update.gif]]
  43.     set iconNS::iconImages(queue)   [image create photo             \
  44.             -file [file join "$dirGetleft(icons)" queue.gif]]
  45.     set iconNS::iconImages(exit)    [image create photo             \
  46.             -file [file join "$dirGetleft(icons)" exit.gif]]
  47.  
  48.     set iconNS::iconImages(conf)    [image create photo             \
  49.             -file [file join "$dirGetleft(icons)" conf.gif]]
  50.     set iconNS::iconImages(clear)   [image create photo             \
  51.             -file [file join "$dirGetleft(icons)" clear.gif]]
  52.  
  53.     return
  54. }
  55. }
  56.  
  57. # Virtual event to raise and flat the buttons in the main window
  58. # and logs.
  59.  
  60. event add <<ButtonRaise>> <FocusIn>
  61. event add <<ButtonRaise>> <Enter>
  62.  
  63. event add <<ButtonFlat>>  <FocusOut>
  64. event add <<ButtonFlat>>  <Leave>
  65.  
  66. # And to make the 'Menu' key work
  67.  
  68. switch $getleftState(os) {
  69.     win {
  70.         event add <<MenuKey>> <App>
  71.     }
  72.     unix {
  73.         event add <<MenuKey>> <Menu>
  74.     }
  75. }
  76.  
  77. namespace eval mainWin {
  78.  
  79. ################################################################################
  80. # ShowScrollX - ShowScrollY
  81. #    They substitute the usual 'set' command of the scrollbar that is invoked
  82. #    when a scrollbar changes visibility. This procedure will hide or show
  83. #    the scrollbars as needed. The after commands are there so to prevent
  84. #    scrollbars appearing and disappering due to the apperance/disaperance
  85. #    of the other, which forms a loop that crashes Tcl/Tk.
  86. #
  87. # Parameter
  88. #    first - last: The same as for the 'set' command in a scrollbar.
  89. ################################################################################
  90. proc ShowScrollX {first last} {
  91.     variable mainWin
  92.  
  93.     if {($first<0.02)&&($last==1)} {
  94.         if {[winfo viewable $mainWin(scrollX)]} {
  95.             grid forget $mainWin(scrollX)
  96.         }
  97.     } else {
  98.         if {![winfo viewable $mainWin(scrollX)]} {
  99.             grid $mainWin(scrollX) -in $mainWin(listFrame)        \
  100.                     -row 1 -column 0 -sticky ew
  101.         }
  102.         $mainWin(scrollX) set $first $last
  103.     }
  104.     return
  105. }
  106.  
  107. proc ShowScrollY {first last} {
  108.     variable mainWin
  109.  
  110.     if {($first<0.02)&&($last==1)} {
  111.         if {[winfo viewable $mainWin(scrollY)]} {
  112.             grid forget $mainWin(scrollY)
  113.         }
  114.     } else {
  115.         if {![winfo viewable $mainWin(scrollY)]} {
  116.             grid $mainWin(scrollY) -in $mainWin(listFrame)        \
  117.                     -row 0 -column 1 -sticky ns
  118.         }
  119.         $mainWin(scrollY) set $first $last
  120.      }
  121.     return
  122. }
  123.  
  124. ################################################################################
  125. # ActivateDownloadButtons
  126. #    When invoked activates or disables the taskbar buttons depending on
  127. #    whether we are downloading or not
  128. ################################################################################
  129. proc ActivateDownloadButtons {} {
  130.     variable mainWin
  131.     variable taskbar
  132.     global   getleftState
  133.  
  134.     $mainWin::taskbar(start) configure -state disabled
  135.     $mainWin::taskbar(auto)  configure -state disabled
  136.  
  137.     if {[$mainWin(listbox) size]} {
  138.         if {$getleftState(downloading)==0} {
  139.             set anchor [$mainWin(listbox) curselection]
  140.             if {$anchor!=""} {
  141.                 $mainWin::taskbar(start) configure -state normal
  142.             }
  143.         }
  144.         $mainWin::taskbar(auto)  configure -state normal
  145.     }
  146.     return
  147. }
  148.  
  149. ################################################################################
  150. # ActivateTaskbarButtons
  151. #    When invoked activates or disables the taskbar buttons depending on
  152. #    whether we are downloading or not
  153. ################################################################################
  154. proc ActivateTaskbarButtons {} {
  155.     global getleftState labelDialogs labelMessages
  156.     variable mainWin
  157.  
  158.     if {$getleftState(downloading)==0} {
  159.         set mainWin(ctrFrameLabel)    $labelDialogs(ready)
  160.         set mainWin(tmpCtrFrameLabel) $labelDialogs(ready)
  161.     } else {
  162.         set mainWin(ctrFrameLabel)    "$labelMessages(downloading): $getleftState(url)"
  163.         set mainWin(tmpCtrFrameLabel) "$labelMessages(downloading): $getleftState(url)"
  164.     }
  165.  
  166.     ActivateDownloadButtons
  167.  
  168.     return
  169. }
  170.  
  171. ################################################################################
  172. # DefineTaskbarButtons
  173. #    Defines the buttons in the taskbar.
  174. #
  175. # Parameters
  176. #    The frames for the buttons.
  177. ################################################################################
  178. proc DefineTaskbarButtons {left right} {
  179.     global   labelDialogs labelMenus getleftState
  180.     variable taskbar
  181.  
  182.     iconNS::DefineIconImages
  183.  
  184.     set taskbar(url)   [button $left.url   -image $iconNS::iconImages(url)   \
  185.             -relief flat -bd 1 -command EnterUrl::EnterUrl]
  186.     ::BalloonHelp::set_balloon $taskbar(url) $labelDialogs(enterUrl)
  187.  
  188.     set taskbar(start) [button $left.start -image $iconNS::iconImages(start) \
  189.             -relief flat -bd 1                                               \
  190.             -command  {AutomaticDownload [mainWin::UrlListSelectedUrl]}]
  191.     ::BalloonHelp::set_balloon $taskbar(start) $labelDialogs(start)
  192.  
  193.     set taskbar(auto) [button $left.auto -image $iconNS::iconImages(auto)    \
  194.             -relief flat -bd 1 -command mainWin::SetAutoDownload]
  195.     ::BalloonHelp::set_balloon $taskbar(auto) $labelDialogs(auto)
  196.  
  197.     set taskbar(delay) [button $left.delay -image $iconNS::iconImages(delay) \
  198.             -relief flat -bd 1                                               \
  199.             -command "::Delay::DelayedDownload"]
  200.     if {$getleftState(delaySet)==1} {
  201.         $taskbar(delay) configure -relief sunken
  202.     }    
  203.     ::BalloonHelp::set_balloon $taskbar(delay) $labelDialogs(progDelay)
  204.  
  205.     set taskbar(log)   [button $left.log   -image $iconNS::iconImages(log)   \
  206.             -relief flat -bd 1                                               \
  207.             -command "::getLog::GetLog"]
  208.     ::BalloonHelp::set_balloon $taskbar(log) $labelDialogs(getLog)
  209.  
  210.     set taskbar(fileLog) [button $right.fileLog -image $iconNS::iconImages(fileLog) \
  211.             -relief flat -bd 1 -command ::getLog::FileLog]
  212.     ::BalloonHelp::set_balloon $taskbar(fileLog) $labelDialogs(fileLog)
  213.     set taskbar(help)  [button $right.conf -image $iconNS::iconImages(help)  \
  214.             -relief flat -bd 1 -command Ayuda::Manual]
  215.     ::BalloonHelp::set_balloon $taskbar(help) $labelDialogs(help)
  216.  
  217.     set taskbar(get)   [button $right.get  -image $iconNS::iconImages(get)   \
  218.             -relief flat -bd 1 -command Ayuda::About]
  219.     ::BalloonHelp::set_balloon $taskbar(get) $labelDialogs(about)
  220.  
  221.     foreach {name path} [array get taskbar] {
  222.         bindtags $path "[bindtags $path] taskIcon"
  223.     }
  224.     bind taskIcon <<ButtonRaise>> {
  225.         %W configure -relief raised
  226.         set mainWin::mainWin(tmpCtrFrameLabel) $mainWin::mainWin(ctrFrameLabel)
  227.         set mainWin::mainWin(ctrFrameLabel)    $BalloonHelp::Bulle(%W)
  228.     }
  229.     bind taskIcon <<ButtonFlat>> {
  230.         if {(("%W"==$mainWin::taskbar(auto))&&($::getleftState(autoDown)==1))
  231.                 ||(("%W"==$mainWin::taskbar(delay))&&($::getleftState(delaySet)==1))} {
  232.             %W configure -relief sunken
  233.         } else {
  234.             %W configure -relief flat
  235.         }        
  236.         set mainWin::mainWin(ctrFrameLabel) $mainWin::mainWin(tmpCtrFrameLabel)
  237.     }
  238.  
  239.     foreach {name path} [array get menus] {
  240.         bind $path <FocusOut> "
  241.             $taskbar($name) configure -relief flat
  242.             BalloonHelp::kill_balloon
  243.         "
  244.     }
  245.  
  246.     return
  247. }
  248.  
  249. ################################################################################
  250. # NextToAutoDownload
  251. #    When invoked this procedure will start downloading the next site in the
  252. #    queue, the point here is that urls entered to get the site map are only
  253. #    downloaded up to where the map is done and then left in the queue.
  254. ################################################################################
  255. proc NextToAutoDownload {} {
  256.     global getleftState urlsToDownload dirGetleft
  257.  
  258.     while {[llength $getleftState(urlsToAutoDown)]>0} {
  259.         foreach url $getleftState(urlsToAutoDown) {
  260.             if {$getleftState(autoDown)==0} break
  261.             if {![info exists urlsToDownload($url,options)]} {
  262.                 set urlIndex [lsearch $getleftState(urlsToAutoDown) $url]
  263.                 set getleftState(urlsToAutoDown)                              \
  264.                         [lreplace $getleftState(urlsToAutoDown)               \
  265.                         $urlIndex $urlIndex]
  266.                 continue
  267.             }
  268.             array set optionsTemp $urlsToDownload($url,options)
  269.             if {$optionsTemp(map)==1} {
  270.                 set domain   [lindex [HtmlParser::ParseUrl $url] 1]
  271.                 set domain   [string tolower $domain]
  272.                 set fileName [file join $dirGetleft(conf) $domain.gdt]
  273.                 if {![catch {open "$fileName" r} handle]} {
  274.                     set found 0
  275.                     for {} {![eof $handle]} {} {
  276.                         set line [gets $handle]
  277.                         if {[regexp {\(mapLinks\)} "$line"]} {
  278.                             set found 1
  279.                             break
  280.                         }
  281.                     }
  282.                     close $handle
  283.                     if {$found} {
  284.                         AutomaticDownload $url
  285.                         continue
  286.                     } else {
  287.                         set urlIndex [lsearch $getleftState(urlsToAutoDown) $url]
  288.                         set getleftState(urlsToAutoDown)                          \
  289.                                 [lreplace $getleftState(urlsToAutoDown)           \
  290.                                 $urlIndex $urlIndex]
  291.                         set urlIndex [UrlListUrlIndex $url]
  292.                         $main(listbox) rowconfigure $urlIndex -bg "" -fg ""
  293.                     }
  294.                 }
  295.             }
  296.             AutomaticDownload $url
  297.         }
  298.     }
  299.     catch {wm withdraw $::Ventana::window(top)}
  300.  
  301.     if {$getleftState(autoDown)==1} {
  302.         SetAutoDownload
  303.     }
  304.  
  305.     return
  306. }
  307.  
  308. ################################################################################
  309. # SetAutoDownload
  310. #   When the button in the taskbar is clicked, this procedure enables or
  311. #   disables full atomatic download.
  312. ################################################################################
  313. proc SetAutoDownload {} {
  314.     global getleftState
  315.     variable taskbar
  316.     variable mainWin
  317.  
  318.     if {$getleftState(autoDown)==0} {
  319.         set getleftState(autoDown) 1
  320.         $taskbar(auto) configure -relief sunken
  321.  
  322.         set getleftState(urlsToAutoDown) ""
  323.         set selectedUrls [$mainWin(listbox) curselection]
  324.         if {$selectedUrls==""} {
  325.             set getleftState(urlsToAutoDown) $getleftState(urlQueue)
  326.             set urlNumber [$mainWin(listbox) size]
  327.             for {set i 0} {$i<$urlNumber} {incr i} {
  328.                 $mainWin(listbox) rowconfigure $i -bg blue -fg white
  329.             }
  330.         } else {
  331.             foreach index $selectedUrls {
  332.                 $mainWin(listbox) rowconfigure $index -bg blue -fg white
  333.                 lappend getleftState(urlsToAutoDown)                      \
  334.                         [$mainWin(listbox) cellcget $index,0 -text]    
  335.             }
  336.         }
  337.         if {($getleftState(downloading)==0)                               \
  338.                 &&([llength $getleftState(urlQueue)]>0)} {
  339.             NextToAutoDownload
  340.         }
  341.     } else {
  342.         set getleftState(autoDown) 0
  343.         set getleftState(urlsToAutoDown) ""
  344.         $taskbar(auto) configure -relief flat
  345.         set urlNumber [$mainWin(listbox) size]
  346.         for {set i 0} {$i<$urlNumber} {incr i} {
  347.             $mainWin(listbox) rowconfigure $i -bg "" -fg ""
  348.         }
  349.     }
  350.     return
  351. }
  352.  
  353. ################################################################################
  354. # UrlListUrlIndex
  355. #   Given an Url this procedure returns its index in the url list.
  356. #
  357. # Parameters
  358. #   url: The url to search for.
  359. #
  360. # Returns
  361. #   The index of the url, or -1 if the is none to return
  362. ################################################################################
  363. proc UrlListUrlIndex {url} {
  364.     variable mainWin
  365.  
  366.     set rowNumber [$mainWin(listbox) size]
  367.     for {set i 0} {$i<$rowNumber} {incr i} {
  368.         set site [$mainWin(listbox) cellcget $i,0 -text]
  369.         if {[string match $url $site]} {
  370.             return $i
  371.         }
  372.     }
  373.     return -1
  374. }
  375.  
  376. ################################################################################
  377. # UrlListIncrResume
  378. #   Given an Url this procedure increments the 'Resumed' counter in the
  379. #   main window.
  380. #
  381. # Parameters
  382. #   url: The url that is going to be resumed.
  383. ################################################################################
  384. proc UrlListIncrResume {url} {
  385.     variable mainWin
  386.  
  387.     set index [UrlListUrlIndex $url]
  388.     set i [$mainWin(listbox) cellcget $index,1 -text]
  389.     $mainWin(listbox) cellconfigure $index,1 -text [incr i]
  390.  
  391.     return
  392. }
  393.  
  394. ################################################################################
  395. # UrlListDeselect
  396. #   Invoke this is you no longer want an url of the list to be selected.
  397. #
  398. # Parameters
  399. #   url: The url to deselect.
  400. ################################################################################
  401. proc UrlListDeselect {url} {
  402.     variable mainWin
  403.  
  404.     set urlIndex [UrlListUrlIndex $url]
  405.     $mainWin(listbox) selection clear $urlIndex
  406.     $mainWin(listbox) rowconfigure $urlIndex -bg "" -fg ""
  407.  
  408.     return
  409. }
  410.  
  411. ################################################################################
  412. # UrlListDeleteUrls
  413. #   Invoked when the user want to delete urls in the queue,
  414. #   checks whether it is the url being downloaded, if it isn't it calls
  415. #   'UrlListDeleteEntry' to get it deleted
  416. #
  417. # Parameters
  418. #   urlIndexList: List with the listbox indices of the urls to delete from the
  419. #   queue.
  420. ################################################################################
  421. proc UrlListDeleteUrls {urlIndexList} {
  422.     global getleftState
  423.     variable mainWin
  424.  
  425.     # We start deleting at the last one, so that the other indices don't
  426.     # get altered.
  427.     set urlIndexList [lsort -decreasing -integer $urlIndexList]
  428.     foreach urlIndex $urlIndexList {
  429.         if {[catch {$mainWin(listbox) cellcget $urlIndex,0 -text} url]} {
  430.             continue
  431.         }
  432.         if {($getleftState(downloading)==1)&&($url==$getleftState(url))} {
  433.             continue
  434.         }
  435.         UrlListDeleteEntry $url
  436.     }
  437.  
  438.     return
  439. }
  440.  
  441. ################################################################################
  442. # UrlListDeleteEntry
  443. #   Deletes urls from the url list.
  444. #
  445. # Parameters
  446. #   url: Url to delete from the queue.
  447. ################################################################################
  448. proc UrlListDeleteEntry {url} {
  449.     variable mainWin
  450.     global getleftState urlsToDownload dirGetleft
  451.  
  452.     set urlIndex [UrlListUrlIndex $url]
  453.     $mainWin(listbox) delete $urlIndex
  454.  
  455.     set index [lsearch $getleftState(urlQueue) $url]
  456.     set getleftState(urlQueue)                                             \
  457.             [lreplace $getleftState(urlQueue) $index $index]
  458.  
  459.     getLog::UrlLogEnter $url $urlsToDownload($url,dir)                     \
  460.             $urlsToDownload($url,options)
  461.  
  462.     catch {unset urlsToDownload($url)}
  463.     catch {unset urlsToDownload($url,dir)}
  464.     catch {unset urlsToDownload($url,resume)}
  465.     catch {unset urlsToDownload($url,options)}
  466.  
  467.     set domain [string tolower [lindex [HtmlParser::ParseUrl $url] 1]]
  468.     catch {file delete [file join $dirGetleft(conf) $domain.gdt]}
  469.  
  470.     if {$getleftState(autoDown)==1} {
  471.         set index [lsearch $getleftState(urlsToAutoDown) $url]
  472.         if {$index!=-1} {
  473.             set getleftState(urlsToAutoDown)                               \
  474.                     [lreplace $getleftState(urlsToAutoDown) $index $index]
  475.         }
  476.     }
  477.  
  478.     SetResumeSitesMenu
  479.     ActivateDownloadButtons
  480.  
  481.     return
  482. }
  483.  
  484. ################################################################################
  485. # UrlListCopyLink
  486. #   Copies the selected links into the clipboard.
  487. #
  488. # Parameters
  489. #   urlIndexList: List with the indices of the urls to copy.
  490. ################################################################################
  491. proc UrlListCopyLink {urlIndexList} {
  492.     variable mainWin
  493.     global   getleftState
  494.  
  495.     clipboard clear
  496.     foreach urlIndex $urlIndexList {
  497.         clipboard append "[$mainWin(listbox) cellcget $urlIndex,0 -text]"
  498.     }
  499.  
  500.     return
  501. }
  502.  
  503. ################################################################################
  504. # UrlListMoveEntry
  505. #   Moves one of the entry one row up or down.
  506. #
  507. # Parameters
  508. #   urlIndexList: List with the indices of the urls to move.
  509. #   how: '-1' up, '1' down.
  510. ################################################################################
  511. proc UrlListMoveEntry {urlIndexList how} {
  512.     variable mainWin
  513.     global getleftState urlsToDownload
  514.  
  515.     set rowLimit [expr [$mainWin(listbox) size] - 1]
  516.     if {$how==1} {
  517.         set urlIndexList [lsort -decreasing -integer $urlIndexList]
  518.     }
  519.     foreach urlIndex $urlIndexList {
  520.         set url [$mainWin(listbox) cellcget $urlIndex,0 -text]
  521.         set queueIndex [lsearch $getleftState(urlQueue) $url]
  522.  
  523.         if {$how==-1} {
  524.             if {$urlIndex==0}         continue
  525.         } else {
  526.             if {$rowLimit==$urlIndex} continue
  527.         }
  528.  
  529.         $mainWin(listbox) delete $urlIndex
  530.         incr urlIndex $how
  531.         $mainWin(listbox) insert $urlIndex [list                     \
  532.                 $url $urlsToDownload($url,resume)                    \
  533.                 [file nativename $urlsToDownload($url,dir)]]
  534.         $mainWin(listbox) selection set $urlIndex $urlIndex
  535.  
  536.         set getleftState(urlQueue) [lreplace $getleftState(urlQueue) \
  537.             $queueIndex $queueIndex]
  538.         incr queueIndex $how
  539.         set getleftState(urlQueue) [linsert $getleftState(urlQueue)  \
  540.                 $queueIndex $url]
  541.     }
  542.     return
  543. }
  544.  
  545. ################################################################################
  546. # UrlListMoveTopBottom
  547. #   Moves one of the urls to the top or the bottom of the list.
  548. #
  549. # Parameters
  550. #   urlIndexList: The list with the indices of the urls to move.
  551. #   where: Either 'top' or 'bottom', defaults to 'bottom'
  552. ################################################################################
  553. proc UrlListMoveTopBottom {urlIndexList {where bottom}} {
  554.     variable mainWin
  555.     global getleftState urlsToDownload
  556.  
  557.     if {$where=="bottom"} {
  558.         set where end
  559.         set adjust -1
  560.         set moveto 1
  561.     } else {
  562.         set where  0
  563.         set adjust 1
  564.         set moveto 0
  565.         set urlIndexList [lsort -decreasing -integer $urlIndexList]
  566.     }
  567.  
  568.     set moved 0
  569.     foreach urlIndex $urlIndexList {
  570.         set urlIndex [expr $urlIndex + $adjust * $moved]
  571.         incr moved        
  572.         set url [$mainWin(listbox) cellcget $urlIndex,0 -text]
  573.         set queueIndex [lsearch $getleftState(urlQueue) $url]
  574.  
  575.         set rowLimit [expr [$mainWin(listbox) size] - 1]
  576.         if {($rowLimit==$urlIndex)&&($where=="end")} {
  577.             return
  578.         }
  579.         if {($urlIndex==0)&&($where==0)} {
  580.             return
  581.         }
  582.  
  583.         $mainWin(listbox) delete $urlIndex
  584.         $mainWin(listbox) insert $where [list                        \
  585.                 $url $urlsToDownload($url,resume)                    \
  586.                 [file nativename $urlsToDownload($url,dir)]]
  587.  
  588.         set getleftState(urlQueue) [lreplace $getleftState(urlQueue) \
  589.                 $queueIndex $queueIndex]
  590.         set getleftState(urlQueue) [linsert $getleftState(urlQueue)  \
  591.                 $where $url]
  592.     }
  593.     $mainWin(listbox) yview moveto $moveto
  594.     $mainWin(listbox) activate $where
  595.  
  596.     return
  597. }
  598.  
  599. ################################################################################
  600. # UrlListEnterEntry
  601. #   Enters one site into the url list.
  602. #
  603. # Parameters
  604. #   url: The url of the entry to enter.
  605. #   resume: How many times it has been resumed so far.
  606. #   dir: The directory where it is going to be saved.
  607. ################################################################################
  608. proc UrlListEnterEntry {url resume dir} {
  609.     variable mainWin
  610.  
  611.     $mainWin(listbox) insert end [list $url $resume [file nativename $dir]]
  612.     $mainWin(listbox) yview moveto 1
  613.  
  614.     ActivateDownloadButtons
  615.  
  616.     return
  617. }
  618.  
  619. ################################################################################
  620. # UrlListSelectedUrl
  621. #   Returns the url of the selected entry in the list.
  622. ################################################################################
  623. proc UrlListSelectedUrl {} {
  624.     variable mainWin
  625.  
  626.     set anchor [lindex [$mainWin(listbox) curselection] 0]
  627.     if {[catch {$mainWin(listbox) cellcget $anchor,0 -text} url]} {
  628.         return
  629.     }
  630.  
  631.     return $url
  632. }
  633.  
  634. ###############################################################################
  635. # UpdateUrlOptions
  636. #    During a download, if the users changes the options by using the menus,
  637. #    procedure is invoked to make sure, the new chosen options are saved for
  638. #    the site.
  639. ###############################################################################
  640. proc UpdateUrlOptions {} {
  641.     global getleftState urlsToDownload downOptions
  642.  
  643.     if {$getleftState(downloading)==0} return
  644.  
  645.     set urlsToDownload($getleftState(url),options) [array get downOptions]
  646.  
  647.     return
  648. }
  649.  
  650. ################################################################################
  651. # UrlListChangeOptions
  652. #   Change the options for downloading an URL in the urlList.
  653. #
  654. # Parameters
  655. #   parent: The window over which the dialog will appear.
  656. #   urlIndexList: List with the indices of the urls whose options we want to
  657. #   change, it defaults to "", which happens when it is invoked with the icon.
  658. ################################################################################
  659. proc UrlListChangeOptions {parent {urlIndexList ""}} {
  660.     global urlsToDownload getleftState
  661.     variable mainWin
  662.  
  663.     if {$urlIndexList==""} {
  664.         ::Opciones::ChooseOptions ::downOptions $parent
  665.         UpdateUrlOptions
  666.         return
  667.     }
  668.  
  669.     set url [$mainWin(listbox) cellcget [lindex $urlIndexList 0],0 -text]
  670.     array set ::downOptionsTemp $urlsToDownload($url,options)
  671.     set done [::Opciones::ChooseOptions ::downOptionsTemp $parent]
  672.  
  673.     if {$done==1} {
  674.         foreach urlIndex $urlIndexList {
  675.             set url [$mainWin(listbox) cellcget $urlIndex,0 -text]
  676.             set urlsToDownload($url,options) [array get ::downOptionsTemp]
  677.             if {($getleftState(downloading)==1)                             \
  678.                     &&([string match $getleftState(url) $url])} {
  679.                 array set ::downOptions $urlsToDownload($url,options)
  680.             }
  681.         }
  682.     }
  683.  
  684.     return
  685. }
  686.  
  687. ################################################################################
  688. # UrlListGetIndex
  689. #   When the user clicks in the url list, this procedure takes care of selecting
  690. #   the nearest entry and returns its index.
  691. #
  692. # Parameters
  693. #   win: window where you clicked.
  694. #   y: the coordinate where you did it
  695. #
  696. # Returns
  697. #   The index of the url, or -1 if the is none to return
  698. ################################################################################
  699. proc UrlListGetIndex {win y} {
  700.     variable mainWin   
  701.  
  702.     set y [expr "$y + [winfo y $win]"]
  703.     set index [$mainWin(listbox) nearest $y]
  704.     if {$index!=-1} {
  705.         set anchor [$mainWin(listbox) curselection]
  706.         if {[lsearch $anchor $index]==-1} {
  707.             $mainWin(listbox) selection clear 0 end
  708.         }
  709.         $mainWin(listbox) selection set $index $index
  710.     }
  711.     return $index
  712. }
  713.  
  714. ################################################################################
  715. # UrlListRightClick
  716. #   This procedure is invoked when the user right-clicks in the multicolumn
  717. #   list with the sites to download, it makes a context menu pop up with the
  718. #   appropiate options
  719. #
  720. # Parameters
  721. #   win: window where you right-clicked.
  722. #   y,x: the coordinates where you did it for the tablelist widget.
  723. #   X,Y: and for the pop up menu.
  724. ################################################################################
  725. proc UrlListRightClick {win x y X Y} {
  726.     variable mainWin
  727.  
  728.     set index [UrlListGetIndex $win $y]
  729.     if {$index==-1} return
  730.  
  731.     $mainWin(listbox)  activate $index
  732.     UrlListContextMenu $index $X $Y
  733.  
  734.     return
  735. }
  736.  
  737. ################################################################################
  738. # UrlListMenuKey
  739. #   This procedure is invoked when the user presses the menu key in the main 
  740. #   window, it gets the information to make the context menu.
  741. #
  742. # Parameters
  743. #   X,Y: and for the pop up menu.
  744. ################################################################################
  745. proc UrlListMenuKey {X Y} {
  746.     variable mainWin
  747.  
  748.     UrlListContextMenu [$mainWin(listbox) index active] $X $Y
  749.  
  750.     return
  751. }
  752.  
  753. ################################################################################
  754. # UrlListContextMenu
  755. #   When the user, either right-clicks on an entry or presses the menu key,
  756. #   this procedure will take care of popping up the context menu.
  757. #
  758. # Parameters
  759. #   index: Position of the url in the queue.
  760. #   X,Y: Where to pop up the menu.
  761. ################################################################################
  762. proc UrlListContextMenu {index X Y} {
  763.     variable menus
  764.     variable mainWin
  765.     global   getleftState urlsToDownload
  766.  
  767.     ActivateDownloadButtons
  768.  
  769.     set url [$mainWin(listbox) cellcget $index,0 -text]
  770.  
  771.     $menus(rightClick) entryconfigure 0                                 \
  772.             -command "AutomaticDownload $url"
  773.     $menus(rightClick) entryconfigure 2                                 \
  774.             -command {mainWin::UrlListChangeOptions .                   \
  775.                     [$mainWin::mainWin(listbox) curselection]}
  776.     $menus(rightClick) entryconfigure 4                                 \
  777.             -command {mainWin::UrlListCopyLink                          \
  778.                     [$mainWin::mainWin(listbox) curselection]}
  779.     $menus(rightClick) entryconfigure 6                                 \
  780.             -command "Ayuda::InvokeBrowser $url ."
  781.     $menus(rightClick) entryconfigure 8                                 \
  782.             -command {mainWin::UrlListMoveTopBottom                     \
  783.                     [$mainWin::mainWin(listbox) curselection] top}
  784.     $menus(rightClick) entryconfigure 9                                 \
  785.             -command {mainWin::UrlListMoveEntry                         \
  786.                     [$mainWin::mainWin(listbox) curselection] -1}
  787.     $menus(rightClick) entryconfigure 10                                \
  788.             -command {mainWin::UrlListMoveEntry                         \
  789.                     [$mainWin::mainWin(listbox) curselection]  1}
  790.     $menus(rightClick) entryconfigure 11                                \
  791.             -command {mainWin::UrlListMoveTopBottom                     \
  792.                     [$mainWin::mainWin(listbox) curselection] bottom}
  793.     $menus(rightClick) entryconfigure 13                                \
  794.             -command {mainWin::UrlListDeleteUrls                        \
  795.                     [$mainWin::mainWin(listbox) curselection]}
  796.  
  797.     if {$getleftState(downloading)==0} {
  798.         $menus(rightClick) entryconfigure 0  -state normal
  799.         $menus(rightClick) entryconfigure 13 -state normal
  800.     } else {
  801.         $menus(rightClick) entryconfigure 0  -state disable
  802.         if {[string match $url $getleftState(url)]} {
  803.             $menus(rightClick) entryconfigure 13 -state disable
  804.         } else {
  805.             $menus(rightClick) entryconfigure 13 -state normal
  806.         }
  807.     }
  808.     tk_popup $menus(rightClick) $X $Y
  809.  
  810.     return
  811. }
  812.  
  813. ################################################################################
  814. # UrlListDoubleClick
  815. #   This procedure is invoked when the user double-clicks in the multicolumn
  816. #   list with the sites to download, it will try to start downloading the site.
  817. #
  818. # Parameters
  819. #   win: window where you double-clicked.
  820. #   y: the coordinate where you did it
  821. ################################################################################
  822. proc UrlListDoubleClick {win y} {
  823.     variable mainWin
  824.     global getleftState
  825.  
  826.     if {$getleftState(downloading)!=0} return
  827.  
  828.     set index [UrlListGetIndex $win $y]
  829.     if {$index==-1} return
  830.  
  831.     set url [$mainWin(listbox) cellcget $index,0 -text]
  832.  
  833.     AutomaticDownload $url
  834.  
  835.     return
  836. }
  837.  
  838. ###############################################################################
  839. # UrlListClearSel
  840. #    Clears the selection in the site listbox.
  841. ###############################################################################
  842. proc UrlListClearSel {} {
  843.     variable mainWin
  844.  
  845.     $mainWin(listbox) selection clear 0 end
  846.  
  847.     return
  848. }
  849.  
  850. ###############################################################################
  851. # SetResumeSitesMenu
  852. #    Puts the entries in the "Resume Sites" menu.
  853. ###############################################################################
  854. proc SetResumeSitesMenu {} {
  855.     global getleftState
  856.  
  857.     .menus.fichero.resume delete 0 end
  858.  
  859.     foreach site [lsort $getleftState(urlQueue)] {
  860.         .menus.fichero.resume add command -label $site            \
  861.                 -command "AutomaticDownload $site"
  862.     }
  863.     return
  864. }
  865.  
  866. ###############################################################################
  867. # MenusLabels
  868. #    Puts the labels into the menus.
  869. #
  870. # Parameters:
  871. #    labFile: file with the labels in the, hopefully, desired language
  872. ###############################################################################
  873. proc MenusLabels {{labFile ""}} {
  874.     global labelButtons labelTitles labelMessages labelDialogs labelMonths
  875.     global labelMenus indexMenus dirGetleft getleftState
  876.     variable menus
  877.  
  878.     if {$labFile==""} {
  879.         set labFile en
  880.     }
  881.  
  882.     ReadLangFile $labFile
  883.  
  884.     .menus      entryconfigure 1 -label $labelMenus(file)           \
  885.             -underline $indexMenus(file)
  886.     $menus(1)   entryconfigure 0 -label $labelMenus(enterUrl)       \
  887.             -underline $indexMenus(enterUrl)
  888.     $menus(1)   entryconfigure 1 -label $labelMenus(siteMap)        \
  889.             -underline $indexMenus(siteMap)
  890.     $menus(1)   entryconfigure 2 -label $labelMenus(resumeSite)     \
  891.             -underline $indexMenus(resumeSite)
  892.     $menus(1)   entryconfigure 4 -label $labelMenus(exit)           \
  893.             -underline $indexMenus(exit)
  894.  
  895.     .menus      entryconfigure 2 -label $labelMenus(options)        \
  896.             -underline $indexMenus(options)
  897.     $menus(2)   entryconfigure 0 -label $labelMenus(all)            \
  898.             -underline $indexMenus(all)
  899.     $menus(2)   entryconfigure 1 -label $labelMenus(uplinks)        \
  900.             -underline $indexMenus(uplinks)
  901.     $menus(2,0) entryconfigure 0 -label $labelMenus(linksFollow)    \
  902.             -underline $indexMenus(linksFollow)
  903.     $menus(2,0) entryconfigure 1 -label $labelMenus(linksIgnore)    \
  904.             -underline $indexMenus(linksIgnore)
  905.     $menus(2)   entryconfigure 2 -label $labelMenus(levels)         \
  906.             -underline $indexMenus(levels)
  907.     $menus(2,0) entryconfigure 2 -label $labelMenus(linksIgnore)    \
  908.             -underline $indexMenus(linksIgnore)
  909.     $menus(2,1) entryconfigure 0 -label $labelMenus(noLimit)        \
  910.             -underline $indexMenus(noLimit)
  911.     $menus(2)   entryconfigure 3 -label $labelMenus(external)       \
  912.             -underline $indexMenus(external)
  913.     $menus(2,2) entryconfigure 0 -label $labelMenus(linksIgnore)    \
  914.             -underline $indexMenus(linksIgnore)
  915.     $menus(2)   entryconfigure 4 -label $labelMenus(fileFilter)     \
  916.             -underline $indexMenus(fileFilter)
  917.     $menus(2,3) entryconfigure 0 -label $labelMenus(onlyHtml)       \
  918.             -underline $indexMenus(onlyHtml)
  919.     $menus(2,3) entryconfigure 1 -label $labelMenus(images)         \
  920.             -underline $indexMenus(images)
  921.     $menus(2,3,1) entryconfigure 0 -label $labelMenus(allImages)    \
  922.             -underline $indexMenus(allImages)
  923.     $menus(2,3,1) entryconfigure 1 -label $labelMenus(onlyThumb)    \
  924.             -underline $indexMenus(onlyThumb)
  925.     $menus(2,3,1) entryconfigure 2 -label $labelMenus(noThumb)      \
  926.             -underline $indexMenus(noThumb)
  927.     $menus(2,3) entryconfigure 2 -label $labelMenus(chooseFilter)   \
  928.             -underline $indexMenus(chooseFilter)
  929.     $menus(2)   entryconfigure 5 -label $labelMenus(resume)         \
  930.             -underline $indexMenus(resume)
  931.     $menus(2)   entryconfigure 6 -label $labelMenus(update)         \
  932.             -underline $indexMenus(update)
  933.     $menus(2)   entryconfigure 7 -label $labelMenus(cgi)            \
  934.             -underline $indexMenus(cgi)
  935.     $menus(2)   entryconfigure 8 -label $labelMenus(useProxy)       \
  936.             -underline $indexMenus(useProxy)
  937.  
  938.     .menus      entryconfigure 3 -label $labelMenus(tools)          \
  939.             -underline $indexMenus(tools)
  940.     $menus(3)   entryconfigure 0 -label $labelMenus(purgeFiles)     \
  941.             -underline $indexMenus(purgeFiles)
  942.     $menus(3)   entryconfigure 1 -label $labelMenus(restoreOrig)    \
  943.             -underline $indexMenus(restoreOrig)
  944.     $menus(3)   entryconfigure 2 -label $labelMenus(configureProxy) \
  945.             -underline $indexMenus(configureProxy)
  946.     $menus(3)   entryconfigure 3 -label $labelMenus(getLog)         \
  947.             -underline $indexMenus(getLog)
  948.     $menus(3)   entryconfigure 4 -label $labelMenus(languages)      \
  949.             -underline $indexMenus(languages)
  950.     $menus(3)   entryconfigure 5 -label Iconos                      \
  951.             -underline $indexMenus(languages)
  952.     if {$getleftState(os)=="unix"} {
  953.         $menus(3)   entryconfigure 6 -label $labelMenus(browser)    \
  954.                 -underline $indexMenus(browser)
  955.     }
  956.  
  957.     .menus      entryconfigure 4 -label $labelMenus(help)           \
  958.             -underline $indexMenus(help)
  959.     $menus(4)   entryconfigure 0 -label $labelMenus(manual)         \
  960.             -underline $indexMenus(manual)
  961.     $menus(4)   entryconfigure 2 -label $labelMenus(changes)        \
  962.             -underline $indexMenus(changes)
  963.     $menus(4)   entryconfigure 3 -label $labelMenus(license)        \
  964.             -underline $indexMenus(license)
  965.     $menus(4)   entryconfigure 5 -label $labelMenus(about)          \
  966.             -underline $indexMenus(about)
  967.  
  968.     return
  969. }
  970.  
  971. ###############################################################################
  972. # ShowMenu1
  973. #    Before posting the file menu, this procedure decides which entries
  974. #    should be active and which will have to wait
  975. ###############################################################################
  976. proc ShowMenu1 {} {
  977.     global getleftState getleftOptions
  978.  
  979.     if {$getleftState(downloading)==0} {
  980.         .menus.fichero entryconfigure 2 -state normal
  981.         if {[llength $getleftState(urlQueue)]==0} {
  982.             .menus.fichero entryconfigure 2 -state disabled
  983.         }
  984.     } else {
  985.         .menus.fichero entryconfigure 2 -state disabled
  986.     }
  987.  
  988.     return
  989. }
  990.  
  991. ###############################################################################
  992. # CreateMenus
  993. #   Creates the menus, without putting the labels
  994. ###############################################################################
  995. proc CreateMenus {} {
  996.     global getleftOptions dirGetleft supportedLang getleftState
  997.     variable menus
  998.  
  999.     menu .menus -relief flat
  1000.     . config -menu .menus
  1001.  
  1002.     set menus(1) [menu .menus.fichero      -tearoff 0                    \
  1003.             -postcommand mainWin::ShowMenu1]
  1004.     .menus add cascade -menu $menus(1)
  1005.     set menus(2) [menu .menus.editar       -tearoff 0]
  1006.     .menus add cascade -menu $menus(2)
  1007.     set menus(3) [menu .menus.herramientas -tearoff 0]
  1008.     .menus add cascade -menu $menus(3)
  1009.     set menus(4) [menu .menus.help         -tearoff 0]
  1010.     .menus add cascade -menu $menus(4)
  1011.  
  1012.     $menus(1) add command -command  EnterUrl::EnterUrl
  1013.     $menus(1) add command -command "EnterUrl::EnterUrl 1"
  1014.     $menus(1) add cascade -menu $menus(1).resume
  1015.     $menus(1) add separator
  1016.     $menus(1) add command -command ExitGetleft
  1017.  
  1018.     set menus(1,2) [menu $menus(1).resume -tearoff 0]
  1019.     SetResumeSitesMenu
  1020.  
  1021.     $menus(2) add command -command "mainWin::UrlListChangeOptions ."
  1022.     $menus(2) add cascade -menu $menus(2).directorios
  1023.     $menus(2) add cascade -menu $menus(2).levels
  1024.     $menus(2) add cascade -menu $menus(2).exLevels
  1025.     $menus(2) add cascade -menu $menus(2).filters
  1026.     $menus(2) add check   -variable downOptions(resume)   -onvalue 1 -offvalue 0 
  1027.     $menus(2) add check   -variable downOptions(update)   -onvalue 1 -offvalue 0 \
  1028.         -command {
  1029.             mainWin::UpdateUrlOptions
  1030.             catch {unset urlsDownloaded}
  1031.         }
  1032.     $menus(2) add check   -variable downOptions(cgi)      -onvalue 1 -offvalue 0 \
  1033.         -command {
  1034.             mainWin::UpdateUrlOptions
  1035.             catch {unset urlsDownloaded}
  1036.         }
  1037.     $menus(2) add check   -variable getleftOptions(proxy) -onvalue 1 -offvalue 0
  1038.  
  1039.     set menus(2,0) [menu $menus(2).directorios -tearoff 0]
  1040.     $menus(2,0) add radio -variable downOptions(dir) -value 1             \
  1041.             -command {
  1042.                 mainWin::UpdateUrlOptions
  1043.                 catch {unset urlsDownloaded}
  1044.             }
  1045.     $menus(2,0) add radio -variable downOptions(dir) -value 0             \
  1046.             -command {
  1047.                 mainWin::UpdateUrlOptions
  1048.                 catch {unset urlsDownloaded}
  1049.             }
  1050.  
  1051.     set menus(2,1) [menu $menus(2).levels -tearoff 0]
  1052.     $menus(2,1) add radio -variable downOptions(levels) -value -1
  1053.     for {set i 0} {$i<6} {incr i} {
  1054.         $menus(2,1) add radio -label $i -variable downOptions(levels)     \
  1055.                 -value $i -command {
  1056.                               mainWin::UpdateUrlOptions
  1057.                               catch {unset urlsDownloaded}
  1058.                           }
  1059.     }
  1060.  
  1061.     set menus(2,2) [menu $menus(2).exLevels -tearoff 0]
  1062.     $menus(2,2) add radio -variable downOptions(exLevels) -value 0        \
  1063.             -command {
  1064.                 set downOptions(external) 0
  1065.                 mainWin::UpdateUrlOptions
  1066.                 catch {unset urlsDownloaded}
  1067.             }
  1068.     for {set i 1} {$i<4} {incr i} {
  1069.         $menus(2,2) add radio -label $i -variable downOptions(exLevels)   \
  1070.             -value $i -command {
  1071.                 set downOptions(external) 1
  1072.                 mainWin::UpdateUrlOptions
  1073.                 catch {unset urlsDownloaded}
  1074.             }
  1075.     }
  1076.  
  1077.     set menus(2,3) [menu $menus(2).filters -tearoff 0]
  1078.     $menus(2,3) add check -variable downOptions(onlyHtml)                 \
  1079.                 -onvalue 1 -offvalue 0 -command {
  1080.                     mainWin::UpdateUrlOptions
  1081.                     catch {unset urlsDownloaded}
  1082.                 }
  1083.     $menus(2,3) add cascade -menu $menus(2,3).images
  1084.     $menus(2,3) add command -command {
  1085.                 Herramientas::FilterFiles $downOptions(filter)
  1086.                 mainWin::UpdateUrlOptions
  1087.             }
  1088.     set menus(2,3,1) [menu $menus(2,3).images -tearoff 0]
  1089.     $menus(2,3,1) add radio -variable downOptions(images) -value 0        \
  1090.             -command {
  1091.                 mainWin::UpdateUrlOptions
  1092.                 catch {unset urlsDownloaded}
  1093.             }
  1094.     $menus(2,3,1) add radio -variable downOptions(images) -value 1        \
  1095.             -command {
  1096.                 mainWin::UpdateUrlOptions
  1097.                 catch {unset urlsDownloaded}
  1098.             }
  1099.     $menus(2,3,1) add radio -variable downOptions(images) -value 2        \
  1100.             -command {
  1101.                 mainWin::UpdateUrlOptions
  1102.                 catch {unset urlsDownloaded}
  1103.             }
  1104.  
  1105.     $menus(3) add command -command Herramientas::PurgeFiles
  1106.     $menus(3) add command -command Herramientas::RestoreOriginals
  1107.     $menus(3) add command -command Herramientas::ConfProxy
  1108.     $menus(3) add command -command getLog::FileLog
  1109.     $menus(3) add cascade -menu $menus(3).idiomas
  1110.     $menus(3) add cascade -menu $menus(3).icons
  1111.  
  1112.     if {$getleftState(os)=="unix"} {
  1113.         $menus(3) add command -command "Ayuda::ChooseLinuxBrowser"
  1114.     }
  1115.  
  1116.     set menus(3,0) [menu $menus(3).idiomas -tearoff 0]
  1117.     set i 0
  1118.     foreach lang $supportedLang(langList) {
  1119.         if {[file exists [file join $dirGetleft(languages)                \
  1120.                 menus.$supportedLang($lang)]]} {
  1121.             $menus(3,0) add command                                       \
  1122.                     -command "ChangeLanguage $supportedLang($lang)"
  1123.             $menus(3,0) entryconfigure $i -label $lang
  1124.             incr i
  1125.         }
  1126.     }
  1127.  
  1128.     set menus(3,1) [menu $menus(3).icons -tearoff 0]
  1129.     foreach iconSet [lsort [glob $dirGetleft(images)/*/]] {
  1130.         $menus(3,1) add radio -variable dirGetleft(icons)                 \
  1131.             -value [string trimright $iconSet /]                          \
  1132.             -label [file tail $iconSet] -command "
  1133.                 ChangeIconSet
  1134.             "
  1135.     }    
  1136.  
  1137.     $menus(4) add command -command Ayuda::Manual
  1138.     $menus(4) add separator
  1139.     $menus(4) add command -command Ayuda::Changes
  1140.     $menus(4) add command -command Ayuda::Licence
  1141.     $menus(4) add separator
  1142.     $menus(4) add command -command Ayuda::About
  1143.  
  1144.     MenusLabels $getleftOptions(lang)
  1145.  
  1146.     return
  1147. }
  1148.  
  1149. ###############################################################################
  1150. # MainWindow
  1151. #    Defines how the main window of Getleft looks.
  1152. ###############################################################################
  1153. proc MainWindow {} {
  1154.     global   getleftState getleftOptions urlsToDownload labelMenus labelDialogs
  1155.     global   dirGetleft   tcl_patchLevel indexMenus
  1156.     variable menus
  1157.     variable taskbar
  1158.     variable mainWin
  1159.  
  1160.     wm title    . "Getleft v1.1.2"
  1161.     wm minsize  . 300 165
  1162.     wm geometry . 660x280
  1163.  
  1164.     if {[winfo exists .menus]} {
  1165.         destroy .menus
  1166.         destroy .menu
  1167.         destroy .extFrame
  1168.     }
  1169.  
  1170.     CreateMenus
  1171.  
  1172.     set extFrame  [frame .extFrame]
  1173.     set iconFrame [frame $extFrame.iconFrame]
  1174.     set listFrame [frame $extFrame.listFrame -bd 2 -relief sunken]
  1175.     set ctrFrame  [frame $extFrame.ctrFrame]
  1176.  
  1177.     set mainWin(listFrame) $listFrame
  1178.  
  1179.     set leftIconFrame  [frame $iconFrame.left ]
  1180.     set rightIconFrame [frame $iconFrame.right]
  1181.     DefineTaskbarButtons $leftIconFrame $rightIconFrame
  1182.  
  1183.     set mainWin(scrollY) [scrollbar $listFrame.scrolly -orient vertical    \
  1184.             -command  [list $listFrame.listbox yview]]
  1185.     set mainWin(scrollX) [scrollbar $listFrame.scrollx -orient horizontal  \
  1186.             -command  [list $listFrame.listbox xview]]
  1187.  
  1188.     set mainWin(listbox) [::tablelist::tablelist $listFrame.listbox        \
  1189.             -bd 0 -height 10 -width 90 -stretch 3 -selectmode extended     \
  1190.             -fg $getleftOptions(fg) -bg $getleftOptions(bg)                \
  1191.             -columns [list 44 $labelDialogs(url)      left                 \
  1192.                             0 $labelDialogs(resumed)  center               \
  1193.                            20 $labelDialogs(localDir) left]                \
  1194.             -xscrollcommand mainWin::ShowScrollX                           \
  1195.             -yscrollcommand mainWin::ShowScrollY                           \
  1196.             -exportselection 0]
  1197.  
  1198.     set intCtrFrame [frame $ctrFrame.int -bd 2 -relief sunken]
  1199.     set ctrLabel    [label $intCtrFrame.label                              \
  1200.         -textvariable mainWin::mainWin(ctrFrameLabel)]
  1201.  
  1202.     set backColor [$intCtrFrame cget -background]
  1203.     $ctrLabel          configure -bg      $backColor
  1204.     $mainWin(listbox)  configure -labelbg $backColor
  1205.  
  1206.     grid $extFrame       -row 0 -sticky news
  1207.     grid $iconFrame             -sticky ew   -padx 5
  1208.     grid $rightIconFrame -row 0 -sticky e
  1209.     grid $leftIconFrame  -row 0 -sticky w
  1210.     grid $taskbar(url)     $taskbar(start) $taskbar(auto) $taskbar(delay)  \
  1211.          $taskbar(log)   
  1212.     grid $taskbar(fileLog) $taskbar(help)  $taskbar(get)  -sticky e
  1213.     grid columnconfigure   $iconFrame 0 -weight 1
  1214.     grid $listFrame -sticky news -pady 2
  1215.     grid $mainWin(listbox) -in $listFrame -row 0 -column 0 -sticky news    \
  1216.             -padx 0 -pady 0
  1217.  
  1218.     grid rowconfigure    .          0 -weight 1
  1219.     grid columnconfigure .          0 -weight 1
  1220.     grid columnconfigure $extFrame  0 -weight 1
  1221.     grid columnconfigure $listFrame 0 -weight 1
  1222.     grid columnconfigure $listFrame 1 -weight 0 -minsize 0
  1223.     grid rowconfigure    $listFrame 0 -weight 1
  1224.     grid rowconfigure    $listFrame 1 -weight 0 -minsize 0
  1225.  
  1226.     grid $ctrFrame       -sticky news
  1227.     grid $intCtrFrame    -sticky news
  1228.     grid $ctrLabel       -sticky w
  1229.     grid rowconfigure    $extFrame 0    -weight 0
  1230.     grid rowconfigure    $extFrame 1    -weight 1
  1231.     grid rowconfigure    $extFrame 2    -weight 0
  1232.     grid columnconfigure $ctrFrame 0    -weight 1
  1233.     grid columnconfigure $intCtrFrame 0 -weight 1
  1234.  
  1235.     grid propagate $listFrame 0
  1236.  
  1237.     if {![info exists getleftState(urlQueue)]} {
  1238.         return
  1239.     }
  1240.  
  1241.     set listboxPath [$mainWin(listbox) bodypath]
  1242.  
  1243.     bind $listboxPath <Double-Button-1> {
  1244.         mainWin::UrlListDoubleClick %W %y
  1245.     }
  1246.     bind $listboxPath <Button-3> {
  1247.         mainWin::UrlListRightClick %W %x %y %X %Y
  1248.     }
  1249.     bind $listboxPath <Return> {
  1250.         mainWin::UrlListDoubleClick %W %y
  1251.     }
  1252.     bind $listboxPath <KP_Enter> {
  1253.         mainWin::UrlListDoubleClick %W %y
  1254.     }
  1255.     bind $listboxPath <FocusIn> {
  1256. #        $mainWin::mainWin(listbox) selection clear 0 end
  1257. #        $mainWin::mainWin(listbox) selection set active
  1258.         mainWin::ActivateDownloadButtons
  1259.     }
  1260.     bind $listboxPath <KeyRelease-Next> {
  1261.         $mainWin::mainWin(listbox) selection clear 0 end
  1262.         $mainWin::mainWin(listbox) selection set active
  1263.     }
  1264.     bind $listboxPath <KeyRelease-Prior> {
  1265.         $mainWin::mainWin(listbox) selection clear 0 end
  1266.         $mainWin::mainWin(listbox) selection set active
  1267.     }
  1268.     bind . <Escape> {
  1269.         $mainWin::mainWin(listbox) selection clear 0 end
  1270.     }
  1271.     bind . <Key-Delete> {
  1272.         mainWin::UrlListDeleteUrls [$mainWin::mainWin(listbox) curselection]
  1273.         $mainWin::mainWin(listbox) selection set active
  1274.     }
  1275.     bind . <<ListboxSelect>> {
  1276.         mainWin::ActivateDownloadButtons
  1277.     }
  1278.     bind . <Control-e> {
  1279.         $mainWin::mainWin(listbox) selection set 0 end
  1280.     }
  1281.     bind . <Control-E> {
  1282.         $mainWin::mainWin(listbox) selection set 0 end
  1283.     }
  1284.     bind . <Control-a> {
  1285.         $mainWin::mainWin(listbox) selection set 0 end
  1286.     }
  1287.     bind . <Control-A> {
  1288.         $mainWin::mainWin(listbox) selection set 0 end
  1289.     }
  1290.     bind . <<MenuKey>> {mainWin::UrlListMenuKey %X %Y}
  1291.  
  1292.     wm protocol . WM_DELETE_WINDOW {
  1293.         ExitGetleft
  1294.     }
  1295.  
  1296.     # Bindings for the whole app.
  1297.     bind Button      <Return>   {%W invoke}
  1298.     bind Button      <KP_Enter> {%W invoke}
  1299.     bind Radiobutton <KP_Enter> {%W invoke}
  1300.     bind Checkbutton <KP_Enter> {%W invoke}
  1301.  
  1302.     foreach site $getleftState(urlQueue) {
  1303.         UrlListEnterEntry $site $urlsToDownload($site,resume)              \
  1304.                                 $urlsToDownload($site,dir)
  1305.     }
  1306.     $mainWin(listbox) yview moveto 0
  1307.  
  1308.     ActivateTaskbarButtons
  1309.  
  1310.     set menus(rightClick) [menu .menu -tearoff 0]
  1311.     $menus(rightClick) add command -label $labelMenus(resume)              \
  1312.             -underline $indexMenus(resume)
  1313.     $menus(rightClick) add separator
  1314.     $menus(rightClick) add command -label $labelMenus(options)             \
  1315.             -underline $indexMenus(options)
  1316.     $menus(rightClick) add separator
  1317.     $menus(rightClick) add command -label $labelMenus(copyLink)            \
  1318.             -underline $indexMenus(copyLink)
  1319.     $menus(rightClick) add separator
  1320.     $menus(rightClick) add command -label $labelMenus(launchLink)          \
  1321.             -underline $indexMenus(launchLink)
  1322.     $menus(rightClick) add separator
  1323.     $menus(rightClick) add command -label $labelMenus(top)                 \
  1324.             -underline $indexMenus(top)
  1325.     $menus(rightClick) add command -label $labelMenus(up)                  \
  1326.             -underline $indexMenus(up)
  1327.     $menus(rightClick) add command -label $labelMenus(down)                \
  1328.             -underline $indexMenus(down)
  1329.     $menus(rightClick) add command -label $labelMenus(bottom)              \
  1330.             -underline $indexMenus(bottom)
  1331.     $menus(rightClick) add separator
  1332.     $menus(rightClick) add command -label $labelMenus(delete)              \
  1333.             -underline $indexMenus(delete)
  1334.  
  1335.     if {$getleftState(os)=="win"} {
  1336.         if {[regexp {((8\.3\.)(3|4))||(8.4)} $tcl_patchLevel]} {
  1337.             catch {wm iconbitmap . -default [file join $dirGetleft(images) icon.ico]}
  1338.         }
  1339.     }
  1340.  
  1341.     focus [$mainWin(listbox) bodypath]
  1342.  
  1343.     return
  1344. }
  1345. }
  1346.